Xbasic

SQL::ResultSetToString Method

Syntax

List as C = ToString([RowsToCopy = -1 as N [, StartRow = -1 as N [, DisplayFormat = .t. as L [, ColumnSeparator as C [, RowSeparator as C, [, ReferenceColumns as SQL::TableInfo [, UserContext as P]]]]]])

Arguments

RowsToCopyNumeric

Default = -1 (all). The number of rows to copy.

StartRowNumeric

Default = 1 (first). The first row to copy.

DisplayFormatLogical

Default = .t.. Indicates whether or not data should be formatted for display in a page or dialog. If .f., data will not be formatted. If .t., data fields such as binary data and logical fields will be formatted for best display in a page or dialog. IE:

  • Binary data is displayed as the literal "<binary data>"" rather than being embedded in the generated output.
  • Logical data will display as T or F rather than .t. and .f..
  • Date, time, and datetime values will be displayed in the default date display format rather than the canonical format (such as YYYY-MM-DD).
  • Geography types will be converted to Well-Known-Text format.
ColumnSeparatorCharacter

Default = "\t" (tab character). The separator used between column values.

RowSeparatorCharacter

Default = crlf() (newline). The separator used between rows.

ReferenceColumnsSQL::TableInfo

When data is formatted for a column in the result set: (1) if ReferenceColumns has a column with a matching name, that object will be used to format the data; (2) otherwise the ColumnInfo property of the result set is used to format the data.

UserContextPointer

The user context is passed into the evaluation of the expression when data is formatted.

Returns

ListCharacter

A tab and CR-LF delimited list of fields and records.

Description

Copy the ResultSet to a string.

Discussion

The ToString() method copies the SQL::ResultSet to a tab and CR-LF delimited list.

Generating a CR-LF delimited list of customers from 'Spain' in the Northwind customers table.
dim cn as SQL::Connection
dim cr as SQL::CallResult
dim args as SQL::Arguments
dim sql as C = "select * from customers where country = :country"
args.set("country","Spain")

if (cn.open("::name::AADemo-Northwind")) then
    if (cn.execute(sql,args)) then
        dim results as c
        results = cn.resultSet.toString()
        showvar(results)
    else
        cr = cn.CallResult
        ui_msg_box("error",cr.text)
    end if
    cn.close()
else
    cr = cn.CallResult
    ui_msg_box("error",cr.text)
end if